package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250224131227CreateAttachmentsTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250224131227CreateAttachmentsTable) Signature() string {
	return "20250224131227_create_attachments_table"
}

// Up Run the migrations.
func (r *M20250224131227CreateAttachmentsTable) Up() error {
	if !facades.Schema().HasTable("attachments") {
		return facades.Schema().Create("attachments", func(table schema.Blueprint) {
			table.ID()
			table.UnsignedBigInteger("attachment_category_id").Comment("父级id")
			table.String("name")
			table.UnsignedBigInteger("user_id")
			table.String("att_dir").Comment("附件路径")
			table.String("att_size").Comment("附件大小")
			table.String("att_type").Comment("附件类型")
			table.SmallInteger("image_type").Comment("1本地 2七牛云 3OSS 4COS").Default(1)
			table.String("url").Comment("URL完整路径")
			table.Enum("upload_way", []any{"local", "oss", "cos", "other"})
			table.String("real_name").Comment("原始文件名")
			table.Foreign("attachment_category_id").References("id").On("attachment_categories").NoActionOnDelete()
			table.SoftDeletes("deleted_at")
			table.Timestamps()
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250224131227CreateAttachmentsTable) Down() error {
	return facades.Schema().DropIfExists("attachments")
}
